package com.rockwell.robot2015.model.states;

import com.rockwell.robot2015.model.RobotAction;
import com.rockwell.robot2015.model.states.running.RobotRunningStateMachine;

public enum RobotState implements IState {
	Initial {

		@Override
		public void enter(IStateMachine machine) {
		}

		@Override
		public void move(IStateMachine machine) {
			machine.robot().initialize();
			
			machine.changeState(Initialized);
		}

		@Override
		public void exit(IStateMachine machine) {
		}
		
	},
	Initialized {

		@Override
		public void enter(IStateMachine machine) {
			machine.robot().ensureArmAtHome();
		}

		@Override
		public void move(IStateMachine machine) {
			//machine.changeState(Running);
		}

		@Override
		public void exit(IStateMachine machine) {
		}
		
	},
	Running {
		@Override
		public void enter(IStateMachine machine) {
			m_runningMachine.afterResume();
			machine.robot().log("Enter Running state", 2);
		}

		@Override
		public void move(IStateMachine machine) {
			m_runningMachine.move();
		}

		@Override
		public void exit(IStateMachine machine) {
			// do nothing
		}
		
	}, 
	Paused {

		@Override
		public void enter(IStateMachine machine) {
			machine.robot().log("In Paused.enter()", 2);
			
			m_runningMachine.beforePause();
		}

		@Override
		public void move(IStateMachine machine) {
			machine.robot().log("In Paused.move()", 2);
			machine.waitForResume();
		}

		@Override
		public void exit(IStateMachine machine) {
		}
		
	},
	Stopped {

		@Override
		public void enter(IStateMachine machine) {
			// Send Stop comment
			machine.robot().log("Enter Stopped state", 2);
			machine.robot().sendCommand(RobotAction.Stop);
		}

		@Override
		public void move(IStateMachine machine) {
			machine.robot().sleep(200);
		}

		@Override
		public void exit(IStateMachine machine) {
		}
		
	};
	
	static RobotRunningStateMachine m_runningMachine;
	
	public static void setRunningMachine(RobotRunningStateMachine running) {
		m_runningMachine = running;
	}
}

